﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AfterlifeLib.GameScreens;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Content;
using AfterlifeLib.GameScreens.Menus;

namespace Afterlife.Screens
{
    public class MainMenuScreen : MenuScreen
    {
        ContentManager content;

        Song backgroundSong;

        public MainMenuScreen()
            : base("Main Menu")
        {
            MenuEntry newGameMenuEntry = new MenuEntry("New Game");
            MenuEntry optionsMenuEntry = new MenuEntry("Options");
            MenuEntry creditsMenuEntry = new MenuEntry("Credits");
            MenuEntry exitMenuEntry = new MenuEntry("Exit");

            newGameMenuEntry.Selected += NewGameMenuEntrySelected;
            optionsMenuEntry.Selected += OptionsMenuEntrySelected;
            creditsMenuEntry.Selected += CreditsMenuEntrySelected;
            exitMenuEntry.Selected += ExitMenuEntrySelected;

            MenuEntries.Add(newGameMenuEntry);
            MenuEntries.Add(optionsMenuEntry);
            MenuEntries.Add(creditsMenuEntry);
            MenuEntries.Add(exitMenuEntry);
        }

        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            backgroundSong = content.Load<Song>("Music/Redletter");

            MediaPlayer.Play(backgroundSong);
        }

        void NewGameMenuEntrySelected(object sender, EventArgs e)
        {
            LoadingScreen.Load(ScreenManager, false, null, new GamePlayScreen());
        }

        void OptionsMenuEntrySelected(object sender, EventArgs e)
        {
            ScreenManager.AddScreen(new MainOptionsScreen(false));
        }

        void CreditsMenuEntrySelected(object sender, EventArgs e)
        {
            ScreenManager.AddScreen(new CreditsScreen());
        }

        void ExitMenuEntrySelected(object sender, EventArgs e)
        {
            ScreenManager.Game.Exit();
        }
    }
}
